//
//  UIView+Extension.swift
//  TinyShopKeeper
//
//  Created by rimi on 16/6/1.
//  Copyright © 2016年 yuying. All rights reserved.
//

import Foundation
import UIKit
extension UIView{
   
    
    func addLeftRadiusLayer(frame:CGRect,rdius:CGFloat){
         _ =  frame .size
        let y = CGRectGetMinY(frame)
        let x = CGRectGetMinX(frame)
        let bezierPath = UIBezierPath()
        bezierPath .moveToPoint(CGPointMake(x+rdius, y))
        //右上角
        bezierPath .addLineToPoint(CGPointMake(CGRectGetMaxX(frame), y))
        //右下角
        bezierPath.addLineToPoint(CGPointMake(CGRectGetMaxX(frame), CGRectGetMaxY(frame)))
        //左下角
        bezierPath.addLineToPoint(CGPointMake(x, CGRectGetMaxY(frame)))
        
        bezierPath.addLineToPoint(CGPointMake(x, y+rdius))
        
        
        //画圆弧 
        //1 圆的中心点 2 半径 3 开始位置 4 结束位置 5 是否为顺时针
        bezierPath.addArcWithCenter(frame.origin, radius: rdius, startAngle: CGFloat(M_PI/2), endAngle: 0, clockwise: false)
        //封闭路径
        bezierPath.closePath()

        let shapLayer = CAShapeLayer()
        shapLayer.path = bezierPath.CGPath
        
        //线颜色
        shapLayer.strokeColor = UIColor.whiteColor().CGColor
        //线宽
        shapLayer.lineWidth = 1;
        //填充颜色
        shapLayer.fillColor = UIColor.whiteColor().CGColor
        self.layer.insertSublayer(shapLayer, atIndex: 0)
    }
    
    
}

